std::tuple_size<std::tuple>
From Cppreference
| C++ Standard Library | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | ||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||
| std::tuple | ||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||
| Defined in header <tuple>
| ||
| template< class T >
class tuple_size; /*undefined*/ | (1) | |
| template< class... Types >
class tuple_size<tuple<Types...> > | (2) | |
| template< class T >
class tuple_size<const T> | (3) | |
| template< class T >
class tuple_size< volatile T > | (4) | |
| template< class T >
class tuple_size< const volatile T > | (5) | |
Provides access to the number of elements in a tuple as a compile-time constant expression.
Contents |
Inherited from std::integral_constant
Members | |
| value | a constant of type std::size_t and value sizeof...(Types) (public static member constant) |
[edit] Example
#include <iostream> #include <tuple> template<class T> void test(T t) { int a[std::tuple_size<T>::value]; // can be used at compile time std::cout << std::tuple_size<T>::value << '\n'; // or at run time } int main() { test(std::make_tuple(1, 2, 3.14)); }
Output:
3
[edit] See also
| accesses specified element (function template) | ||
| obtains the type of the specified element (class template specialization) | ||
| obtains the size of a pair (class template specialization) | ||